#!/usr/bin/env bash
#
# Summary: Show information about which command will be executed
#
# Usage: jenv info <command>
#


set -e
[ -n "$JENV_DEBUG" ] && set -x     


            
exportedValues=""

exportVariable(){   
   exportedValues="$exportedValues:$1"
   export $1="$2 $3 $4 $5 $6 $7 $8 $9"
    
}

# Provide jenv completions
if [ "$1" = "--complete" ]; then
  exec jenv shims --short
fi

export JENV_VERSION="$(jenv-version-name)"    
            
export JENV_OPTIONS="$(jenv-options)"    



JENV_COMMAND="$1"              

export JAVA_HOME="$JENV_ROOT/versions/$JENV_VERSION"    
          

JENV_COMMAND_PATH="$(jenv-which "$JENV_COMMAND")"
JENV_BIN_PATH="${JENV_COMMAND_PATH%/*}"

for script in $(jenv-hooks exec); do
  source "$script"
done

shift 1
if [ "$JENV_VERSION" != "system" ]; then
  export PATH="${JENV_BIN_PATH}:${PATH}"
fi
echo "Jenv will exec : $JENV_COMMAND_PATH" $JENV_OPTIONS "$@"   
#echo $exportedValues          
echo "Exported variables :"
echo "  JAVA_HOME=$JAVA_HOME"
while IFS=':' read -ra ADDR; do
      for i in "${ADDR[@]}"; do
      	  if [ -n "$i" ]; then
   				echo "  $i=${!i}" 
		  fi
      done
 done <<< "$exportedValues"
